package cn.ekuma.impexp.model.transform;

import java.util.List;

import cn.ekuma.impexp.model.AbstractImpExpTableDefinition;
import cn.ekuma.impexp.ui.swing.ColumnMatch;

public class ExportColumnMatchTableTransform extends AbstractTableTransform{

	List<ColumnMatch> filter;
	int[] filterFieldIndex;
	
	public ExportColumnMatchTableTransform(AbstractImpExpTableDefinition table,List<ColumnMatch> filter) {
		super(table);
		this.filter=filter;
		filterTable();
	}

	@Override
	public Object[] getData(int rowIndex) {
		Object[] dscDatas=new Object[filter.size()];
		ColumnMatch columnMatch;
		Object[] srcDate=defaultTable.getData(rowIndex);
		System.out.println("原的数据为：");
		println(srcDate);
		System.out.println("过滤数量："+filter.size());
		for(int i=0;i<filter.size();i++){
			columnMatch=filter.get(i);
			String defValue=columnMatch.getDefValue();
			if(defValue==null)
				defValue="";
			if((!defValue.isEmpty())&&(!columnMatch.isJustChangeNullValue()||columnMatch.isJustChangeNullValue()&&defValue.isEmpty()))
				  dscDatas[i]=columnMatch.getDefValue();
			else if(columnMatch.getFidldGenerator()!=null&&(!columnMatch.isJustChangeNullValue()||columnMatch.isJustChangeNullValue()&&defValue.isEmpty()))
				  dscDatas[i]=columnMatch.getFidldGenerator().getNext();
			else
				dscDatas[i]=srcDate[columnMatch.getDestCol()];
		}
		System.out.println("生成的数据为：");
		println(dscDatas);
		return dscDatas;
	}

	@Override
	public int[] getFieldIndexs() {
		return filterFieldIndex;
	}

	@Override
	public int[] getUpdateFieldIndexs() {
		return filterFieldIndex;
	}

	private void println(Object[] rowDate){
		for(int i=0;i<filter.size();i++){
			System.out.println(rowDate[i]+"\t");
		}
		System.out.println("\n");
	}
	
	public void filterTable(){
		filterFieldIndex=new int[filter.size()];
		for(int i=0;i<filter.size();i++){
			filterFieldIndex[i]=filter.get(i).getSrcCol();
		}
	}
	
}
